//区间合并写法
#include <iostream>
#include <algorithm>

#define x first
#define y second

using namespace std;

const int N = 5010;

typedef pair<int, int> PII;

PII q[N];

int n;

int max_1, max_2;


int main()
{
    cin >> n;
    
    for (int i = 0; i < n; i ++ ) cin >> q[i].x >> q[i].y;
    
    sort(q, q + n);
    
    int l = -2e9, r = -2e9;
    
    for (int i = 0; i < n; i ++ )
    {
        if (r < q[i].x)
        {
            if(l != -2e9)
            {
            max_2 = max(q[i].x - r, max_2);
            max_1 = max(r - l, max_1);
            r = q[i].x;
            }
            
        l = q[i].x, r = q[i].y;
            
        }
        else r = max(q[i].y, r);
    }
    
    if(l != -2e9) max_1 = max(r - l, max_1);
    
    cout << max_1 << ' ' << max_2 << endl;
    
}
//-----------------------------------------------------------------

//离散化+差分

#include <iostream>
#include <vector>
#include <algorithm>

#define x first
#define y second

using namespace std;

typedef pair<int, int> PII;

const int N = 10010;

vector<int> pos;
PII g[N];
int cnt[N];

int n;

int max_1, max_2;

bool check(int mid, int t)
{
    return pos[mid] >= t;
}

int find(int t)
{
    int l = 0, r = pos.size() - 1;
    
    while (l < r)
    {
        int mid = l + r >> 1;
        if (check(mid, t)) r = mid;
        else l = mid + 1;
    }
    
    return r;
}

int main()
{
    cin >> n;
    
    for (int i = 0; i < n; i ++ )
    {
        int l, r;
        cin >> l >> r;
        
        g[i] = {l, r};
        
        pos.push_back(l), pos.push_back(r);
    }
    
    sort(pos.begin(), pos.end());
    pos.erase(unique(pos.begin(), pos.end()), pos.end());
    
    for (int i = 0; i < n; i ++ )
    {
        cnt[find(g[i].x)] ++ ;
        cnt[find(g[i].y)] -- ;
    }
    
    int c = 0;
    int last = 0;
    
    for (int i = 0; i < pos.size(); i ++ )
    {
        if (i) 
        {
            if (c == 0) last = i;
            if (c + cnt[i] == 0)
            {
                max_1 = max(pos[i] - pos[last], max_1);
                if (i != pos.size() - 1) max_2 = max(pos[i + 1] - pos[i], max_2);
            }
        }
        
        c += cnt[i];
        
    }
    
    cout << max_1 << ' ' << max_2 << endl;
    
    return 0;
}

//利用map（红黑树）来进行离散化
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

#define x first
#define y second

using namespace std;

typedef pair<int, int> PII;

const int N = 10010;

map<int, int> mp;

int n;

int max_1, max_2;

int main()
{
    cin >> n;
    
    for (int i = 0; i < n; i ++ )
    {
        int l, r;
        cin >> l >> r;
        
        mp[l] ++ ;
        mp[r] -- ;
        
    }

    int c = 0;
    int last = 0;
    int en = 0;
    
    bool flag = false;
    
    for (auto a : mp)
    {
        if (flag) 
        {
            
            if (c == 0) 
            {
                max_2 = max(a.x - en, max_2);
                last = a.x;
            }
            if (c + a.y == 0)
            {
                max_1 = max(a.x - last, max_1);
                en = a.x;
            }
        }
        if (!flag)
        {
            last = a.x;
        }
        c += a.y;
        flag = true;
    }
    
    cout << max_1 << ' ' << max_2 << endl;
    
    return 0;
}